<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('资源配置列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <!--                            <li disabled="true">-->
                        <!--                                <label>uuid：</label>-->
                        <!--                                <input type="text" name="uuid"/>-->
                        <!--                            </li>-->
                        <li>
                            <label>环境编码：</label>
                            <input type="text" name="resenvcode"/>
                        </li>
                        <li>
                            <label>主机/IP：</label>
                            <input type="text" name="reshost"/>
                        </li>
                        <!--                            <li>-->
                        <!--                                <label>密码：</label>-->
                        <!--                                <input type="text" name="respassword"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>端口：</label>-->
                        <!--                                <input type="text" name="resport"/>-->
                        <!--                            </li>-->
                        <li>
                            <label>用户名：</label>
                            <input type="text" name="resusername"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="devops:resources:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="devops:resources:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="devops:resources:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="devops:resources:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-info" onclick="batAdd()"
               shiro:hasPermission="ddevops:resources:batAdd">
                <i class="fa glyphicon glyphicon-list"></i> 批量导入
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('devops:resources:edit')}]];
    var removeFlag = [[${@permission.hasPermi('devops:resources:remove')}]];
    var prefix = ctx + "devops/resources";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "资源配置",
            columns: [{
                checkbox: true
            },
                {
                    field: 'uuid',
                    title: 'uuid'
                },
                {
                    field: 'resenvcode',
                    title: '资源所属环境'
                },
                {
                    field: 'reshost',
                    title: '主机/IP'
                },
                {
                    field: 'resusername',
                    title: '用户名'
                },
                {
                    field: 'respassword',
                    title: '密码'
                },
                {
                    field: 'resport',
                    title: '端口'
                },
                {
                    field: 'status',
                    title: '状态 0-失效 1-生效'
                },
                {
                    field: 'remark',
                    title: 'remark'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.uuid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.uuid + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });
</script>
</body>
<script type="text/javascript">
    function getEnvList() {
        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "devops/env/list",
            data: {},
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                log.info(data);
            }
        });
    };
    function batAdd() {

        layer.prompt({
            formType: 2, //输入框类型，支持0（文本）默认1（密码）2（多行文本）
            value: '', //初始时的值，默认空字符
            maxlength: 500,//可输入文本的最大长度，默认500
            title: '格式：环境编码|IP|用户名|密码|备注  回车解析下一条数据', //标题
            area: ['600px', '250px'] //自定义文本域宽高
        }, function(value, index, elem){
            // value 为输入的内容

            $.ajax({
                cache: true,
                type: "POST",
                url: ctx + "devops/resources/batAdd",
                data: {info : value},
                async: false,
                error: function (request) {
                    $.modal.alertError("系统错误");
                },
                success: function (data) {
                    log.info(data);
                }
            });
            $.table.refresh();
            layer.close(index);
        });

    }
</script>
</html>